//
//  SetViewController.m
//  ITrip
//
//  Created by dllo on 15/5/26.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "SetViewController.h"
#import <SDImageCache.h>
#import "StrategyViewController.h"
#import <UMFeedback.h>

#define USERDEFAULT [NSUserDefaults standardUserDefaults]
@interface SetViewController ()<UITableViewDataSource, UITableViewDelegate>
{
    UITableView *tView;
}

@property(nonatomic, retain) UILabel *label;


@end

@implementation SetViewController

- (void)dealloc
{
    [_label release];
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.tabBarController.tabBar.hidden  = YES;
    self.tabBarController.tabBar.translucent = YES;
    UIImage *icon = [UIImage imageNamed:@"iconfont_return"];
    icon = [icon imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStyleDone target:self action:@selector(getBack)];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 110, 30)];
    title.text = @"  设     置";
    title.font = [UIFont systemFontOfSize:20];
    title.font = [UIFont boldSystemFontOfSize:25];
    title.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = title;
    
    self.view.backgroundColor = [UIColor whiteColor];
     tView = [[UITableView alloc] initWithFrame:CGRectMake(0, 30, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:tView];
    [tView release];
//    tView.backgroundView = bgView;
    tView.delegate = self;
    tView.dataSource = self;
    tView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tView.scrollEnabled = NO;
    
}


- (void)getBack
{
    self.tabBarController.tabBar.hidden  = NO;
    self.tabBarController.tabBar.translucent = NO;
    [self.navigationController popViewControllerAnimated:YES];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
    }
//    if (indexPath.row == 0) {
//        cell.textLabel.text = @"设置导航栏颜色";
//        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
//        UIButton *grayButton = [UIButton buttonWithType:UIButtonTypeCustom];
//        UIButton *blueButton = [UIButton buttonWithType:UIButtonTypeCustom];
//        UIButton *purpleButton = [UIButton buttonWithType:UIButtonTypeCustom];
//        grayButton.backgroundColor = [UIColor grayColor];
//        blueButton.backgroundColor = [UIColor blueColor];
//        purpleButton.backgroundColor = [UIColor purpleColor];
//        grayButton.frame = CGRectMake(0, 0, 60, 50);
//        blueButton.frame = CGRectMake(70, 0, 60, 50);
//        purpleButton.frame = CGRectMake(140, 0, 60, 50);
//        grayButton.tag = 1;
//        blueButton.tag = 2;
//        purpleButton.tag = 3;
//        [view addSubview:grayButton];
//        [view addSubview:blueButton];
//        [view addSubview:purpleButton];
//        [grayButton addTarget:self action:@selector(setColor:) forControlEvents:UIControlEventTouchUpInside];
//        [blueButton addTarget:self action:@selector(setColor:) forControlEvents:UIControlEventTouchUpInside];
//        [purpleButton addTarget:self action:@selector(setColor:) forControlEvents:UIControlEventTouchUpInside];
//        cell.accessoryView = view;
//        
//    } else
//    cell.alpha = 0;
    UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    bgView.image = [UIImage imageNamed:@"375-600_BG"];
    
//    cell.backgroundView = bgView;
    
    cell.textLabel.textColor = [UIColor blackColor];
    if (indexPath.row == 1) {
        cell.textLabel.text = @"意见反馈";
    } else if (indexPath.row == 0) {
        cell.textLabel.text = @"清除图片缓存";
        NSInteger size = [[SDImageCache sharedImageCache] getSize];
        self.label = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 50)] autorelease];
        self.label.text = [NSString stringWithFormat:@"%ld MB", size / (1024 * 1024)];
        cell.accessoryView = self.label;
    }
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(18, 50 * (indexPath.row + 1), 120, 1)];
    view.backgroundColor = [UIColor grayColor];
    [tableView addSubview:view];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 1) {
//        int m_appleID = 1003148434;
//        NSString *str = [NSString stringWithFormat:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa     /wa/viewContentsUserReviews?type=Purple+Software&id=%d", m_appleID];
//        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
        [self presentModalViewController:[UMFeedback feedbackModalViewController]
                                animated:YES];
        
    } else if (indexPath.row == 0) {
        NSInteger size = [[SDImageCache sharedImageCache] getSize];
        [[SDImageCache sharedImageCache] clearDisk];
        self.label.text = [NSString stringWithFormat:@"%ld MB", size / (1024 * 1024)];
        [tView reloadData];
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
